// This File is part of Innovation Foundry's "QualityHelper Project"
//
// Copyright  2008 Innovation Foundry Pty Ltd
// All rights reserved

// This work is free software; you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published 
// by the Free Software Foundation; either version 3 of the License, 
// or any later version. This work is distributed in the hope that 
// it will be useful, but WITHOUT ANY WARRANTY; without even the 
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
// PURPOSE. 
// See version 3 of the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this work; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA  02110-1301 USA
// or alternatively it may be downloaded from <http://www.gnu.org/licenses/>.

//Determines if array
function isArray(testObject) {	 
    return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}

function isFirefox () {
    return (navigator.userAgent.indexOf("Firefox")!=-1);
}

function isIE () {
    return (navigator.userAgent.indexOf("MSIE")!=-1);
}

function convertBoolToInt(boolText) {
    if (boolText == null || !isDefined(boolText))
    {
        return 0;
    }
    if (boolText.toLowerCase() =='true' || boolText == true || boolText =='1' || Number(boolText)== 1) 
    {
        return 1;
    }
    else 
    {
        return 0;
    }
}

var Tracing = true;
var TracingAlerts = false;
function trace(message) {
    try {
        if (Tracing) {
            if (isFirefox() && console) {
                console.log(arguments);
            }
            else if (TracingAlerts) {
                var messageString = null;
                for (var i = 0; i < arguments.length; i++) {
                    messageString += arguments[i] + " ";
                }
                alert(messageString);
            }
        }
    }
    catch (e) { }
}


function LoadSilverlightControl(ctrl, silverlightID, elm) {
    var control = document.getElementById(silverlightID);
    var div = document.getElementById(elm);
    div.style.display = "block";
    control.setAttribute("Source", ctrl);
}

function HideSilverlightControl(silverlightID, elm) {
    var control = document.getElementById(silverlightID);
    var div = document.getElementById(elm);
    div.style.display = "none";
    control.setAttribute("Source", "");

}

function checkForGears(welcomeMessage,returnURL) {
    if (!window.google || !google.gears) {
        location.href = "http://gears.google.com/?action=install&message=" + welcomeMessage + "&return=" + returnURL;
        return 0;
    }
    return 1;
}